﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DotNet.Business;

public partial class admin_addProductClass : System.Web.UI.Page
{
    #region 初始化常量
    tab_productClassBll productClassBll = new tab_productClassBll();
    #endregion
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["action"]!=null)
            {
                string action=Request.QueryString["action"];
                switch (action.Trim())
                {
                    case "add":
                        addProductClass();
                        break;
                    case "edit":
                        this.hid_action.Value = "save";
                        loadProductClass();
                        break;
                    case"save":
                        saveProductClass();
                        break;
                    default:
                        break;
                }
            }
        }
    }
    #region 加载数据
    /// <summary>
    /// 加载数据
    /// </summary>
    public void loadProductClass() 
    {
        int pcid = Convert.ToInt32(Request.QueryString["pcid"]);        
        tab_productClass productClass=productClassBll.GetModel(pcid) as tab_productClass;       
        this.txt_productClassName.Value = productClass.productClassName;
        this.txt_info.Value = productClass.productClassInfo;
        this.txt_title.Value = productClass.productClassTitle;
        this.txt_seoDescription.Value = productClass.productClassDescription;
        this.txt_key.Value = productClass.productClassKey;
        this.hid_id.Value = pcid.ToString();
        
    }
    #endregion

    #region 保存
    public void saveProductClass() 
    {
        int pcid = Convert.ToInt32(Request.Form["pcid"]);
        tab_productClass productClass = new tab_productClass();
        string productClassName = Request.Form["productClassName"];
        string productClassInfo = Request.Form["productClassInfo"];
        productClass.pcid = pcid;
        productClass.productClassName = productClassName;
        productClass.productClassInfo = productClassInfo;
        productClass.productClassTitle = Request.Form["title"].ToString();
        productClass.productClassDescription = Request.Form["description"].ToString();
        productClass.productClassKey = Request.Form["key"].ToString();
        if (productClassBll.Update(productClass)) 
        {
            Response.Write("2");
            Response.End();
        }

    }
    #endregion

    #region 添加
    /// <summary>
    /// 添加
    /// </summary>
    public void addProductClass() 
    {
        bool bo = false;
        string productClassName = Request.Form["productClassName"];
        string productClassInfo = Request.Form["productClassInfo"];
        tab_productClass productClass = new tab_productClass();
        productClass.productClassName = productClassName;
        productClass.productClassInfo = productClassInfo;
        productClass.productClassTitle = Request.Form["title"].ToString();
        productClass.productClassDescription = Request.Form["description"].ToString();
        productClass.productClassKey = Request.Form["key"].ToString();
        productClass.productClassDate = DateTime.Now;
        bo=productClassBll.Insert(productClass);
        if (bo)
        {
            Response.Write("1");
            Response.End();
        }
    }
    #endregion
}
